package com.example.springDemo.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.mail.internet.MimeMessage;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class MailBox {
    @Autowired
    JavaMailSender javaMailSender;

    @RequestMapping("/sms/email")
    void sendEmail(){
        try{
            String email = "to";
            SimpleMailMessage message = new SimpleMailMessage();

            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
//            helper.addAttachment();

            message.setFrom("1852974658@qq.com");
            message.setSubject("这是你的验证码");
            message.setReplyTo("ReplyTo");
            message.setTo(email);
            String s = UUID.randomUUID().toString();
            message.setText(s);
            javaMailSender.send(message);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
